package com.cym.utils;

import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import org.springframework.core.io.ClassPathResource;

import cn.hutool.core.io.IoUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

public class JapaneseUtils {

	public static String toJapanese(String keyword) {
		try {
			ClassPathResource resource = new ClassPathResource("file/japan.json");
			InputStream inputStream = resource.getInputStream();
			JSONObject json = JSONUtil.parseObj(IoUtil.read(inputStream, Charset.forName("utf-8")));

			char[] chars = keyword.toCharArray();
			StringBuffer stringBuffer = new StringBuffer();
			for (char c : chars) {
				String s = String.valueOf(c);
				if (json.containsKey(s)) {
					stringBuffer.append(json.getStr(s));
				} else {
					stringBuffer.append(s);
				}
			}

			return stringBuffer.toString();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return keyword;
	}

}
